package cz.muni.fi.pa165.soap;

import cz.muni.fi.pa165.dto.CustomerDTO;
import cz.muni.fi.pa165.login.Authenticator;
import cz.muni.fi.pa165.service.local.impl.CustomerService;
import java.util.List;
import javax.inject.Inject;
import javax.jws.WebService;

/**
 *
 * @author <a href="mailto:vramik at redhat.com">Vlastislav Ramik</a>
 */
@WebService(endpointInterface = "cz.muni.fi.pa165.soap.CustomerSoapService", serviceName = "customerService")
public class CustomerSoapServiceImpl implements CustomerSoapService {

    @Inject
    CustomerService customerService;

    @Inject
    Authenticator a;
    private String id="4";
    private String pass="rest";
    
    private void login(){
        a.setUsername(this.id);
        a.setPassword(pass);
        a.login();
    }
    
    @Override
    public CustomerDTO getCustomer(Long id) {
        login();
        return customerService.getCustomerById(id);
    }

    @Override
    public List<CustomerDTO> getCustomers() {
        login();
        return customerService.getAllCustomers();
    }

    @Override
    public Long createCustomer(CustomerDTO customer) {
        login();
        return customerService.createCustomer(customer);
    }

    @Override
    public void removeCustomer(CustomerDTO customer) {
        login();
        customerService.removeCustomer(customer);
    }

    @Override
    public void updateCustomer(CustomerDTO customer) {
        login();
        customerService.updateCustomer(customer);
    }
}
